import {fetchGoodsListAPI} from "@/api/productListApi";

const actions = {
    /* 获取商品搜索结果列表的action */
    async fetchGoodsList(context, {onReachBottom, params}) {
        const {message} = await fetchGoodsListAPI(params)
        context.commit("updateGoodsList", {onReachBottom, message})
    }
}
const mutations = {
    /* 更新商品搜索结果列表的mutations */
    updateGoodsList(state, {onReachBottom, message}) {
        state.total = message.total
        if (onReachBottom) {
            state.goodsList = [...state.goodsList, ...message.goods]
        } else {
            state.goodsList = message.goods
        }
    }
}
const state = () => {
    return {
        goodsList: [],
        total: 0,
    }
}
const getters = {}

export default {
    namespaced: true,
    actions,
    mutations,
    state,
    getters
}
